package com.rpc.center.manager;

import com.rpc.center.entity.ConsumerNode;
import com.rpc.center.entity.PublisherNode;
import com.rpc.common.entity.HostInfoPair;
import io.netty.channel.Channel;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * RPC服务管理器
 */
@Service
@Setter
@Getter
public class RPCServiceManager {
    @Autowired
    private RPCServiceStore serviceStore;

    @Autowired
    private RPCSubscribeManager subscribeManager;

    public void regist(String serviceID, PublisherNode publisherNode) {
        serviceStore.registService(serviceID, publisherNode);
    }

    public List<PublisherNode> searchService(String serviceID) {
        return serviceStore.searchService(serviceID);
    }

    public PublisherNode getPublisherByChannel(Channel channel){
        return serviceStore.getPublisherByChannel(channel);
    }

    private RPCServiceManager(){

    }
    private static RPCServiceManager manager=new RPCServiceManager();

    public static RPCServiceManager getServiceManager(){
        return manager;
    }

    public void addSubscriber(String serviceID,ConsumerNode consumerNode){
        subscribeManager.addSubscriber(serviceID,consumerNode);
    }

    public boolean removeSubscriber(String serviceID,ConsumerNode consumerNode){
        return subscribeManager.removeSubscriber(serviceID,consumerNode);
    }

    public List<ConsumerNode> getSubscriberList(String serviceID){
        return subscribeManager.getSubscribeList(serviceID);
    }
}
